package com.snapan.config;

import com.snapan.interceptor.LogInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    // 注册拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 添加登录拦截器
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/**") // 拦截所有路径
                .excludePathPatterns( // 排除不拦截的路径
                        "/login",
                        "/api/user/**",
                        "/user/login",
                        "/user/register",
                        "/css/**",
                        "/js/**",
                        "/images/**",
                        "/api/verification/**",
                        "/forgetPassword"

                );


    }
//      "/api/user/login",//登录
//              "/forgetPassword", // 新增：放行重置密码页面
//              "/registration",// 新增：放行注册页面
//              "/api/user/info",//更新用户信息
//              "/api/user/{id}/storage",//查询用户存储使用情况（已用/总空间，单位：字节）
//              "/api/user/check-email",//查邮箱是否已存在
//              "/api/user/register",//用户注册接口
//              "/api/user/update-password"//修改密码

    // 配置静态资源放行（与XML的<mvc:resources>等效）
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/css/**").addResourceLocations("/css/");
        registry.addResourceHandler("/js/**").addResourceLocations("/js/");
        registry.addResourceHandler("/images/**").addResourceLocations("/images/");
    }
}